 package com.superpai.view.custom; 

import android.app.Dialog;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.WindowManager;
import android.widget.ImageView;

import com.superpai.R;

/**
 * @author Devin.Hu
 * @date 2011-9-17
 * @version V1.0
 * @description 商品详情图片对话框
 */
public class ProductImageDialog extends Dialog {

	protected Context mContext;
	private ImageView mImageView;
	private Drawable showDrawable;
	
	public ProductImageDialog(Context context) {
		 this(context, android.R.style.Theme_Translucent_NoTitleBar);
		 this.mContext = context;
	}

	protected ProductImageDialog(Context context, int theme) {
        super(context, theme);
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		WindowManager.LayoutParams lp=getWindow().getAttributes();
		lp.flags = android.view.WindowManager.LayoutParams.FLAG_DIM_BEHIND;
		lp.dimAmount = 0.7f;
		getWindow().setAttributes(lp);
				
		this.setContentView(R.layout.product_image_dialog);
		
		mImageView = (ImageView)this.findViewById(R.id.product_gimage);
		mImageView.setBackgroundDrawable(showDrawable);
	}

	@Override
	public boolean onTouchEvent(MotionEvent event) {
		
		if(event.getAction() == MotionEvent.ACTION_UP){
			this.cancel();
		}
		return super.onTouchEvent(event);
	}
	
	public void setShowDrawable(Drawable drawable){
		this.showDrawable = drawable;
		
		if(mImageView!=null){
			mImageView.setBackgroundDrawable(showDrawable);
		}
	}

	@Override
	protected void onStop() {
		super.onStop();
		
		mImageView.setBackgroundDrawable(null);
		showDrawable = null;
		mContext = null;
	}
}
